cmake_minimum_required(VERSION 3.16)
set(MCU_TOOLCHAIN_PATH /config/riscv/gcc/)
set(MCU_TARGET_TRIPLET "riscv-none-elf")
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/mcu_gcc.cmake)
set(CMAKE_SYSTEM_PROCESSOR riscv)
set(MCU_TYPE "CH32V30x")
project(ch32v307 C CXX ASM)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 99)

# 头文件路径
include_directories(APP
                    Core
                    Debug 
                    Peripheral/inc)


# 源码文件
file(GLOB_RECURSE SOURCES 
                "APP/*.c"
                "Core/core_riscv.c" 
                "Debug/debug.c"
                "Peripheral/src/*.c"      
       )
set(STARTUP_ASM "Startup/startup_ch32v30x_D8C.S")
# 链接参数
set(LINKER_SCRIPT  ${CMAKE_SOURCE_DIR}/Ld/Link.ld)

set(PROJECT_SOURCES
    ${SOURCES}
    ${STARTUP_ASM}
)

message("#########################################")
message( "DEVICE: ${MCU_TYPE}" )
message("#########################################")


add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} )
target_link_libraries(${PROJECT_NAME} MCU::NoSys ${MCU_TYPE})
target_link_libraries(${PROJECT_NAME} MCU::Nano ${MCU_TYPE})


target_compile_options(${PROJECT_NAME} PUBLIC "-Os")
mcu_add_linker_script(${PROJECT_NAME} PUBLIC ${LINKER_SCRIPT})


target_link_options(${PROJECT_NAME} PUBLIC -Xlinker -Map=${PROJECT_NAME}.map)

mcu_generate_binary_file(${PROJECT_NAME})
mcu_generate_dump_file(${PROJECT_NAME})
mcu_print_size_of_target(${PROJECT_NAME})



# 编译等级
add_compile_options(-O2)
